/**
 * 商机明细添加开窗
 * @author miaoyl
 * @date 2019/04/18
 */
define(function () {

    var self,
        doc = document,
        app = win.app,
        layui = win.layui,
        element,
        table,
        table_where = {

        },
        cols = [[
            {type:'checkbox'},
            {field: 'GWAM001', width: 160, title: '商品编号'}
            , {field: 'GWAML003', width: 140, title: '品名'}
            , {field: 'GWAML004', width: 140, title: '规格'}
            , {field: 'GWAP100', width: 140, title: '单价'}
            , {field: 'GWAM008', width: 140, title: '销售单位'}
        ]],
        cb
    ;

    var Gwat160Edit = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwat160_edit_gwbk',
            }, win);
        },

        _call:function (obj) {
            //self.tableReload();
            cb = obj.cb;
        },

        initTable: function () {
            layui.use(['table'], function () {
                table = layui.table;
                table.render({
                    elem: app.getByid(doc, 'gwat160_edit_gwbk_table'),
                    url: g_ctxPath + 'crm/gwat160/getGwamData',
                    id: 'gwat160_edit_gwbk_table',
                    height: 'full',
                    cols: cols,
                    loading: true,
                    page: true,
                    where: table_where
                });

                var tipsIndex = null;

                $(doc).on('click', function () {
                    tipsIndex && layer.close(tipsIndex);
                });

            });
        },

        tableReload: function(){
            self._reloadTable({id: 'gwat160_edit_gwbk_table', where: table_where});
        },

        _ready: function () {
            var vue = new Vue({
                el: '#gwat160_edit_gwbk',
                data: '',
                methods: {
                    cancel:function () {
                        self._closeTpl();
                    },
                    sure:function () {
                        var checkStatus = table.checkStatus('gwat160_edit_gwbk_table');
                        cb(checkStatus.data);
                        self._closeTpl();
                    }
                },
                created: function () {
                    self._setEleIsReady('gwat160_edit_gwbk');
                }
            });

            self.initTable();
        },

        _lazy: function () {
            this._super();
            layui.use(['table'], function () {
                element = layui.element;
            });
        }
    });

    return new Gwat160Edit();

});